package com.lishiots.cloud.datacenter.middleware.web;

import com.lishiots.cloud.datacenter.middleware.common.BuildResult;
import com.lishiots.cloud.datacenter.middleware.service.MaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

/**
 * Created by Chaofan at 2018-11-22 15:14
 * email:chaofan2685@qq.com
 **/

@Api(value = "资源管理",tags = "资源管理")
@RestController
@RequestMapping("/api")
public class MaterialController extends BuildResult {


    @Autowired
    MaterialService materialService;

    @ApiImplicitParams({
            @ApiImplicitParam(value = "上传文件",name = "file",required = true,allowMultiple = true,dataType = "MultipartFile")
    })
    @PostMapping(value = "/upload")
    @ApiOperation(value = "Layui编辑器上传资源")
    public Map<String,Object> upload(@RequestParam(value="file") MultipartFile file){
        return materialService.addFiles(file);
    }

    @ApiImplicitParams({
            @ApiImplicitParam(value = "上传文件",name = "editormd-image-file",required = true,allowMultiple = true,dataType = "MultipartFile")
    })
    @PostMapping(value = "/upload2")
    @ApiOperation(value = "MarkDown编辑器上传资源")
    public Map<String,Object> upload2(@RequestParam(value="editormd-image-file") MultipartFile file){
        Map<String,Object> result = materialService.addFiles(file);
        result.put("success",result.get("status"));
        result.remove("status");
        result.put("message",result.get("msg"));
        result.remove("msg");
        return result;
    }


}
